<template>
  <div class="app-container calendar-list-container">
    <custom-card title="认证申请" class="mt-10">
      <template>
        <basic-form v-if="!loading" :basicInfo="basicForm" :detail="detail" ref="basicForm" :lang="language"></basic-form>
      </template>
    </custom-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import * as baseApi from '@/api/common/index'
import * as prodApi from '@/api/product/index'
import * as planApi from '@/api/cert/plan/index'
import BasicForm from '@/components/BasicForm/showDetail';
export default {
  components: {
    BasicForm
  },
  data() {
    return {
      loading: true,
      basicForm: [
        {
          label: '申请类型',
          element: 'select',
          name: 'applyTypeId'
        }, {
          label: '申请人',
          element: 'input',
          name: 'createUserName'
        }, {
          label: '申请部门',
          element: 'input',
          name: 'createUserDepart'
        }, {
          label: '项目编号',
          element: 'input',
          name: 'projectNo',
        }, {
          label: '产品型号',
          element: 'input',
          name: 'plmModelNo',
        }, {
          label: '产品名称',
          element: 'input',
          name: 'productName',
        }, {
          label: '主办业务',
          element: 'input',
          name: 'hostingBusiness',
        }, {
          label: '申请原因',
          element: 'textarea',
          name: 'applyReason',
        }, {
          label: '证书种类',
          element: 'checkbox-remark',
          name: 'pdsCertApplyCategoriesList',
        }, {
          label: '客户编号',
          element: 'input',
          name: 'customerNo',
        }, {
          label: '客户型号',
          element: 'input',
          name: 'customerModelNo',
        }, {
          label: '币别',
          element: 'select',
          name: 'currencyDv',
        }, {
          label: '预计费用',
          element: 'input',
          name: 'estimatedCost',
        }, {
          label: '持证单位',
          element: 'select',
          name: 'certLicensedUnitId',
          value: 'id',
          labelName: 'name'
        }, {
          label: '持证单位名称',
          element: 'input',
          name: 'companyName',
        }, {
          label: '持证单位地址',
          element: 'input',
          name: 'companyAddress',
        }, {
          label: '费用承担方',
          element: 'textarea',
          name: '',
        }, {
          label: '亚特比例',
          element: 'input',
          name: 'costBearerYat',
        }, {
          label: '客户比例',
          element: 'input',
          name: 'costBearerCustomer',
        }, {
          label: '供应商比例',
          element: 'input',
          name: 'costBearerSupplier',
        }, {
          label: '样品预计完成日期',
          element: 'datePicker',
          name: 'sampleEndDate',
        }, {
          label: '申请要求完成日期',
          element: 'datePicker',
          name: 'applyEndDate',
        }
      ],
      detail: {}
    }
  },
  computed: {
    ...mapGetters(['elements', 'language'])
  },
  created() {
    this.getOptions()
  },
  activated() {
    this.getDetail();
  },
  methods: {
    getDetail() {
      planApi.getCertPlanDetail(this.$route.query.id).then(res => {
        if (res.code == 200) {
          this.detail = res.data.pdsCertApply;
          this.detail.pdsCertApplyCategoriesList = res.data.pdsCertApplyCategoriesList;
          this.basicForm[13].options.map(item => {
            if (this.detail.certLicensedUnitId == item.id) {
              this.detail.companyName = item.companyName;
              this.detail.companyAddress = item.companyAddress;
            }
          })
          this.loading = false;
        }
      })
    },
    getOptions() {
      /* 产品类型 */
      baseApi.getTypeValue('cert_dict_apply_type').then(res => {
        this.basicForm[0].options = res.data.rows;
      })
      /* 认证类型 */
      prodApi.certList().then(res => {
        this.basicForm[8].options = res.data;
      })
      /* 币别 */
      baseApi.getTypeValue('cert_dict_currency').then(res => {
        this.basicForm[11].options = res.data.rows;
      })
      /* 持证信息 */
      prodApi.unitList().then(res => {
        this.basicForm[13].options = res.data;
      })
    }
  }
}
</script>
